var table1;
$(function () {
    initTime();
    layui.use('table', function () {
        var table = layui.table;
        table1 = table.render({
            elem: '#cameraTable',
            method: 'post',
            toolbar: '#toolbarDemo',
            contentType: "application/json",
            url: ctx + "/camera/queryByPage",
            title: '相机列表',
            page: true,
            request: {
                pageName: 'currentPage',
                limitName: 'pageSize'
            },
            limit: 10,
            limits: [10, 15, 20, 25, 30],
            height: 'full-120',
            cols: [
                [
                    {
                        title: '序号',align: 'center', width: 50, templet: function (obj) {
                            return obj.LAY_INDEX
                        }
                    },
                    {field: 'sn', align: 'center', width: '180', title: '相机sn'},
                    {
                        field: 'online',
                        align: 'center',
                        title: '相机状态',
                        width: 90,
                        templet: function (d) {
                            if (d.online==0){
                                return '<input type="checkbox" lay-skin="switch" lay-text="在线|不在线"  disabled>'
                            }
                            return '<input type="checkbox" lay-skin="switch" lay-text="在线|不在线" checked disabled>'
                        }
                    },
                    {field: 'name', align: 'center', width: '100', title: '相机名'},
                    {field: 'ip', align: 'center', width: '130', title: 'ip'},
                    {field: 'communityName', align: 'center', width: '160', title: '所属小区'},
                    {field: 'door', align: 'center', width: '80', title: '门'},
                    {
                        field: 'whetherIn',
                        align: 'center',
                        title: '进出口',
                        width: 80,
                        templet: function (d) {
                            return d.whetherIn == 0 ? '<span style="color: #00cc22">' + '进口' + '</span>' :
                                '<span style="color: rgb(204,0,0);">' + '出口' + '</span>'
                        }
                    },
                    {field: 'createTime', align: 'center', width: '180', title: '创建时间'}
                ]
            ]
        });
    });

})

//初始化时间
function initTime() {
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#createTime', //指定元素
            format: 'yyyy-MM-dd HH:mm:ss' //可任意组合
        });
    });
}

//查询
function query() {
    const condition = {name: $("#name").val()}
    table1.reload({
        where: {
            "condition": condition
        }
    });
}

//清空
function clean() {
    $("#name").val('');
    query();
    form.render();
}